import Vue from 'vue'
import router from '@/router/index'
import store from '@/store/index'
import App from './App'
import '@/styles/app.scss'
import '@/plugins/element-ui'
import IM from '@/im' // 融云即时通讯
import Popup from '@/popup'
import { formatTimeStamp, formatSeconds, urlTobase64, parseTime } from '@/utils'
import storage from '@/utils/storage'
import ErrorHandler from '@/utils/error-handler'
import registerSW from '@/workbox/sw-register'

const isUseSW = process.env.NODE_ENV === 'production' // service worker需要https环境,在本地调试中可以设为false关闭此功能;
if (isUseSW) {
  registerSW('sw-redirect.js') // 开启service worker
} else {
  window.dispatchEvent(new CustomEvent('sw.ready', {}))
}

if (process.env.NODE_ENV === 'production') {
  Vue.use(ErrorHandler) // 上传报错信息
}
Vue.use(IM)
Vue.use(Popup)
Vue.prototype._store = store
Vue.prototype.$utils = {
  formatTimeStamp,
  formatSeconds,
  urlTobase64,
  parseTime
}
Vue.prototype.$storage = storage
Vue.prototype.$isUseSW = isUseSW

new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
